<?php

session_start();
require_once('../include/MySugarApplication.php');
require_once("../include/CampaignSoap.php");
$app->checkSession('Campaigns/Form.php');


if ($_REQUEST["actionType"] == "UPDATE") {

	$query=' campaigns.id = "'.$_REQUEST["id"].'"';
	$orderby = '';

	$rows = $contactSoap->getCampaigns($query, 0, 0, $orderby, false);
	
	foreach($rows as $record) {
							
		$array= $app->nameValuePairToSimpleArray($record['name_value_list']);
	
		$id = $array["id"];
		$name = $array["name"];
		$date_entered = $array["date_entered"];
		$date_modified = $array["date_modified"];
		$modified_user_id = $array["modified_user_id"];
		$created_by = $array["created_by"];
		$description = $array["description"];
		$assigned_user_id = $array["assigned_user_id"];
		$opportunity_type = $array["opportunity_type"];
		$campaign_id = $array["campaign_id"];
		$lead_source = $array["lead_source"];
		$amount = $array["amount"];
		$amount_usdollar = $array["amount_usdollar"];
		$currency_id = $array["currency_id"];
		$date_closed = $array["date_closed"];
		$next_step = $array["next_step"];
		$sales_stage = $array["sales_stage"];
		$probability = $array["probability"];
	}
}




?>
<!DOCTYPE HTML SYSTEM "http://www.bitzermobile.com/bitzer/dtd/HTML401-loose-bitzer.dtd">
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<?php
		if (!$isBitzer) {
        	echo '
			<title>MySugar Campaigns</title>
			<LINK REL=StyleSheet HREF="',$app->appRoot,'include/style.css" TYPE="text/css" MEDIA=screen>
        <script type="text/javascript" src="',$app->appRoot,'include/niftycube.js"></script>
        <script type="text/javascript">
            window.onload=function(){
				var formWidth = "550px";
				setAppRoot("',$app->appRoot,'");
                Nifty("div#container");
                Nifty("div#content,div#nav","same-height small");
                Nifty("div#header,div#footer","small");
                Nifty("ul.postnav a","transparent");
				setWidth("div#container", formWidth);
				setWidth("div#content", formWidth);
				setWidth("div#footer", formWidth);
				
				var riWidth = "550px";
                Nifty("div#riContainer");
                Nifty("div#riContent,div#nav","same-height small");
                Nifty("div#riHeader,div#riFooter","small");
                Nifty("ul.postnav a","transparent");
				setWidth("div#riContainer", riWidth);
				setWidth("div#riContent", riWidth);
				setWidth("div#riFooter", riWidth);
            }
        </script>';
        } else {
			echo '<title></title>';
		}
			?>    
    </head>
    <body>
    	<?php
		if (!$isBitzer) {
			echo '
        <div id="container">
            <div id="header">
				<table width="100%">
					<tr>
						<td width="95%"><h1>Campaigns</h1></td>
						<td align="right" width="5%"><a href="',$app->appRoot,'Logout.php">Logout</a></td>
					</tr>
				</table>
			</div>
            <div id="content">
                <h3>Please enter contact info.</h3>';
		}
		?>
                <form name="Campaigns"
                      data-bitzer-title="Campaign"
                      data-bitzer-desc="Campaigns List"
                      data-bitzer-type="COMPONENT"
                      data-bitzer-data-url="<?php echo $app->appRoot ?>Campaigns/Data.php"
                      data-bitzer-pagination="true"
                      action="Save.php" method="POST"
                      enctype="multipart/form-data">
                    <input type="hidden" name="id" value="<?php echo $id ?>"
                           data-bitzer-primary-key="true"
                           data-bitzer-type="integer">
                    <?php 
                    	if ($_REQUEST["actionType"] == "UPDATE" ) {
                    		echo '<input type="hidden" name="actionType" value="UPDATE">';
                    	}
                    ?>
<?php
if (!$isBitzer) {
?>
                    <table class="form" width="100%">
                    	<tr>
                            <th width="27%">
                                <div align="left">
                                    Name
                                </div>
                            </th>
                            <td>
<?php
}
?>
                                <input data-bitzer-label="Name"
                                       data-bitzer-short-label="Name"
                                       data-bitzer-type="string"
                                       data-bitzer-help-text="Name for opportunity"
                                       type="file" name="name"
                                       size="50" value="<?php echo $name ?>"
                                        >
<?php
if (!$isBitzer) {
?>
                            </td>
                        </tr>
                    	<tr>
                            <th width="27%">
                                <div align="left">
                                    Salutation
                                </div>
                            </th>
                            <td>
<?php
}
?>
                                <select data-bitzer-label="Title"
                                		data-bitzer-short-label="Title"
                                        data-bitzer-type="string"
                                        data-bitzer-help-text="Salution to use for contact"
                                        data-bitzer-display-group-name="Personal"
                                        data-bitzer-display-group-order="1"
                                        data-bitzer-display-group-title="" 
                                        name="salutation"  >
                                    <?php
									foreach ($salutationsArray as $key => $label) {
									
										if ($label == $salutation) {
											$selected = "SELECTED";
										} else {
											$selected = "";
										}
										
										echo '<option label="',$label,'" value="',$key,'" ',$selected,' >';
									}
									?>
                                </select>
<?php
if (!$isBitzer) {
?>
                            </td>
                        </tr>
                        <tr>
                            <th width="27%">
                                <div align="left">
                                    First Name
                                </div>
                            </th>
                            <td>
<?php
}
?>
                                <input data-bitzer-label="First Name"
                                       data-bitzer-short-label="First"
                                       data-bitzer-type="string"
                                       data-bitzer-help-text="First name of contact"
                                       type="text" name="first_name"
                                       size="50"
                                       data-bitzer-default-view-column="1"
                                       data-bitzer-display-group-name="Personal"
                                       value="<?php echo $first_name ?>" >
<?php
if (!$isBitzer) {
?>
                            </td>
                        </tr>
                        <tr>
                            <th>
                                <div align="left">
                                    Last Name
                                </div>
                            </th>
                            <td>
<?php
}
?>                            
                                <input data-bitzer-label="Last Name"
                                       data-bitzer-short-label="Last"
                                       data-bitzer-help-text="Last name of contact"
                                       data-bitzer-type="string"
                                       type="text" name="last_name"
                                       data-bitzer-default-view-column="2"
                                       data-bitzer-display-group-name="Personal"
                                       size="50"
                                       value="<?php echo $last_name ?>">
<?php
if (!$isBitzer) {
?>
                            </td>
                        </tr>
                        <tr>
                            <th>
                                <div align="left">
                                    Account
                                </div>
                            </th>
                            <td>
<?php
}
?>                            
                                <select data-bitzer-label="Account"
                                        data-bitzer-type="integer"
                                        data-bitzer-help-text="Account name" 
                                        name="account_id"  
                                        data-bitzer-lookup-component="Accounts"
                                        data-bitzer-short-label="Acct."
                                        data-bitzer-display-group-name="Personal">
                                	<option></option>
                                </select>
<?php
if (!$isBitzer) {
?>
                            </td>
                        </tr>
                        <tr>
                            <th>
                                <div align="left">
                                    Lead Source
                                </div>
                            </th>
                            <td>
<?php
}
?>                            
                                <select data-bitzer-label="Lead Source"
                                        data-bitzer-short-label="Lead"
                                        data-bitzer-type="string"
                                        data-bitzer-help-text="Lead source" 
                                        data-bitzer-display-group-name="Personal"
                                        name="lead_source"  >
                                <?php
									foreach ($leadsArray as $key => $label) {
									
										if ($label == $lead_source)
											$selected = "SELECTED";
										else
											$selected = "";
								
										echo '<option label="',$label,'" value="',$key,'" ',$selected,' >';
									}
								?>
                                	
                                </select>
<?php
if (!$isBitzer) {
?>
                            </td>
                        </tr>
                        <tr>
                            <th>
                                <div align="left">
                                    Campaign
                                </div>
                            </th>
                            <td>
<?php
}
?>                            
                                <select data-bitzer-label="Campaign"
                                        data-bitzer-type="integer"
                                        data-bitzer-help-text="Campaign name" 
                                        name="campaign_id"  
                                        data-bitzer-lookup-component="Campaigns"
                                        data-bitzer-short-label="Camp."
                                        data-bitzer-display-group-name="Personal">
                                	<option></option>
                                </select>
<?php
if (!$isBitzer) {
?>                                
                            </td>
                        </tr>
                        <tr>
                            <th width="27%">
                                <div align="left">
                                    Job Title
                                </div>
                            </th>
                            <td>
<?php
}
?>                            
                                <input data-bitzer-label="Job Title"
                                       data-bitzer-short-label="First"
                                       data-bitzer-type="string"
                                       data-bitzer-help-text="Jbo title"
                                       data-bitzer-display-group-name="Personal"
                                       type="text" name="title"
                                       size="50"
                                       value="<?php echo $title ?>">
<?php
if (!$isBitzer) {
?>                                       
                            </td>
                        </tr>
                        <tr>
                            <th>
                                <div align="left">
                                    Department
                                </div>
                            </th>
                            <td>
<?php
}
?>                            
                                <input data-bitzer-label="Department"
                                       data-bitzer-short-label="Dept."
                                       data-bitzer-help-text="Department name"
                                       data-bitzer-type="string"
                                       data-bitzer-display-group-name="Personal"
                                       type="text" name="department"
                                       size="50"
                                       value="<?php echo $department ?>">
<?php
if (!$isBitzer) {
?>                                       
                            </td>
                        </tr>
                        <tr>
                            <th>
                                <div align="left">
                                    Assigned To
                                </div>
                            </th>
                            <td>
<?php
}
?>                   
                                <select data-bitzer-label="Assigned To"
                                        data-bitzer-short-label="User"
                                        data-bitzer-type="integer"
                                        data-bitzer-help-text="Assigned to user" 
                                        name="assigend_user_id"  
                                        data-bitzer-lookup-component="Users"
                                        data-bitzer-lookup-view="users-default-view"
                                        data-bitzer-lookup-value-field="id"
                                        data-bitzer-display-group-name="Personal"
                                        >
                                	<option></option>
                                </select>
<?php
if (!$isBitzer) {
?>                                                                
                            </td>
                        </tr>
                        <tr>
                            <th>
                                <div align="left">
                                    Email
                                </div>
                            </th>
                            <td>
<?php
}
?>                            
                                <input data-bitzer-label="Email"
                                       data-bitzer-help-text="Email of contact"
                                       data-bitzer-type="email"
                                       data-bitzer-display-group-name="Campaign"
                                       data-bitzer-display-group-order="2"
                                       data-bitzer-display-group-title="Campaign Information"
                                       type="text" name="email1"
                                       size="50"
                                       value="<?php echo $email1 ?>">
<?php
if (!$isBitzer) {
?>                                       
                            </td>
                        </tr>
                        <tr>
                            <th>
                                <div align="left">
                                    Work Phone
                                </div>
                            </th>
                            <td>
<?php
}
?>                            
                                <input data-bitzer-label="Work Phone"
                                	   data-bitzer-short-label="Work"
                                       data-bitzer-help-text="Work Phone of contact"
                                       data-bitzer-display-group-name="Campaign"
                                       data-bitzer-type="tel"
                                       type="text" name="phone_work"
                                       size="50"
                                       value="<?php echo $phone_work ?>">
<?php
if (!$isBitzer) {
?>                                       
                            </td>
                        </tr>
                        <tr>
                            <th>
                                <div align="left">
                                    Mobile Phone
                                </div>
                            </th>
                            <td>
<?php
}
?>                            
                                <input data-bitzer-label="Mobile Phone"
                                       data-bitzer-short-label="Mobile"
                                       data-bitzer-help-text="Mobile Phone of contact"
                                       data-bitzer-display-group-name="Campaign"
                                       data-bitzer-type="tel"
                                       type="text" name="phone_mobile"
                                       size="50"
                                       value="<?php echo $phone_mobile ?>">
<?php
if (!$isBitzer) {
?>                                       
                            </td>
                        </tr>
                        <tr>
                            <th>
                                <div align="left">
                                    Home Phone
                                </div>
                            </th>
                            <td>
<?php
}
?>                            
                                <input data-bitzer-label="Home Phone"
                                       data-bitzer-short-label="Home"
                                       data-bitzer-help-text="Home Phone of contact"
                                       data-bitzer-display-group-name="Campaign"
                                       data-bitzer-type="tel"
                                       type="text" name="phone_home"
                                       size="50"
                                       value="<?php echo $phone_home ?>">
<?php
if (!$isBitzer) {
?>                                       
                            </td>
                        </tr>
                        <tr>
                            <th>
                                <div align="left">
                                    Other Phone
                                </div>
                            </th>
                            <td>
<?php
}
?>                            
                                <input data-bitzer-label="Other Phone"
                                	   data-bitzer-short-label="Other"
                                       data-bitzer-help-text="Other Phone of contact"
                                       data-bitzer-display-group-name="Campaign"
                                       data-bitzer-type="tel"
                                       type="text" name="phone_other"
                                       size="50"
                                       value="<?php echo $phone_other ?>">
<?php
if (!$isBitzer) {
?>                                       
                            </td>
                        </tr>
                        <tr>
                            <th>
                                <div align="left">
                                    Fax
                                </div>
                            </th>
                            <td>
<?php
}
?>                            
                                <input data-bitzer-label="Fax"
                                	   data-bitzer-short-label="Fax"
                                       data-bitzer-help-text="Fax of contact"
                                       data-bitzer-display-group-name="Campaign"
                                       data-bitzer-type="tel"
                                       type="text" name="phone_fax"
                                       size="50"
                                       value="<?php echo $phone_fax ?>">
<?php
if (!$isBitzer) {
?>                                       
                            </td>
                        </tr>
                        <tr>
                            <th>
                                <div align="left">
                                    Do Not Call
                                </div>
                            </th>
                            <td>
<?php
}
?>                            
                                <input data-bitzer-label="Do Not Cal"
                                	   data-bitzer-short-label="Not Call"
                                       data-bitzer-help-text="Does the contact wish not to be called ?"
                                       data-bitzer-display-group-name="Campaign"
                                       data-bitzer-type="boolean"
                                       type="checkbox" name="do_not_call"
                                       <?php if ($do_not_call == "1") echo ' CHECKED '; ?>
                                       >
<?php
if (!$isBitzer) {
?>                                       
                            </td>
                        </tr>
                        <tr>
                            <th>
                                <div align="left">
                                    Primary Street
                                </div>
                            </th>
                            <td>
<?php
}
?>                            
                                <input data-bitzer-label="Street"
                                	   data-bitzer-short-label="Street"
                                       data-bitzer-help-text="Primary street name"
                                       data-bitzer-type="street"
                                       type="text" name="primary_address_street"
                                       size="50"
                                       value="<?php echo $primary_address_street ?>">
<?php
if (!$isBitzer) {
?>                                       
                            </td>
                        </tr>
                        <tr>
                            <th>
                                <div align="left">
                                    Primary City
                                </div>
                            </th>
                            <td>
<?php
}
?>                            
                                <input data-bitzer-label="City"
                                	   data-bitzer-short-label="City"
                                       data-bitzer-help-text="Primary City"
                                       data-bitzer-type="city"
                                       data-bitzer-display-group-name="Address"
                                       data-bitzer-display-group-order="3"
                                       data-bitzer-display-group-title="Primary Address"
                                       type="text" name="primary_address_city"
                                       size="50"
                                       value="<?php echo $primary_address_city ?>">
<?php
if (!$isBitzer) {
?>                                       
                            </td>
                        </tr>
                        <tr>
                            <th>
                                <div align="left">
                                    Primary State
                                </div>
                            </th>
                            <td>
<?php
}
?>                            
                                <input data-bitzer-label="State"
                                	   data-bitzer-short-label="State"
                                       data-bitzer-help-text="Primary state"
                                       data-bitzer-display-group-name="Address"
                                       data-bitzer-type="state"
                                       type="text" name="primary_address_state"
                                       size="50"
                                       value="<?php echo $primary_address_state ?>">
<?php
if (!$isBitzer) {
?>                                       
                            </td>
                        </tr>
                        <tr>
                            <th>
                                <div align="left">
                                    Primary Postal Code
                                </div>
                            </th>
                            <td>
<?php
}
?>                            
                                <input data-bitzer-label="Postal Code"
                                	   data-bitzer-short-label="Zip"
                                       data-bitzer-help-text="Primary postal code"
                                       data-bitzer-display-group-name="Address"
                                       data-bitzer-type="postalCode"
                                       type="text" name="primary_address_postalcode"
                                       size="50"
                                       value="<?php echo $primary_address_postalcode ?>">
<?php
if (!$isBitzer) {
?>                                       
                            </td>
                        </tr>
                        <tr>
                            <th>
                                <div align="left">
                                    Primary Country
                                </div>
                            </th>
                            <td>
<?php
}
?>                            
                                <input data-bitzer-label="Country"
                                	   data-bitzer-short-label="Country"
                                       data-bitzer-help-text="Primary country"
                                       data-bitzer-display-group-name="Address"
                                       data-bitzer-type="country"
                                       type="text" name="primary_address_country"
                                       size="50"
                                       value="<?php echo $primary_address_country ?>">
<?php
if (!$isBitzer) {
?>                                       
                            </td>
                        </tr>
                        <tr>
                            <th>
                                <div align="left">
                                    Description
                                </div>
                            </th>
                            <td>
<?php
}
?>                            
                            	<textarea data-bitzer-label="Description"
                                	   data-bitzer-short-label="Desc."
                                       data-bitzer-help-text="Description for contact"
                                       data-bitzer-display-group-name="Description"
                                       data-bitzer-display-group-order="4"
                                       data-bitzer-display-group-title="Description"
                                       rows="5" cols="40"
									   name="description"><?php echo $description ?></textarea>
<?php
if (!$isBitzer) {
?>                                       
                            </td>
                        </tr>
                        <tr>
                            <th>
                                <div align="left">
                                    Last Modified On
                                </div>
                            </th>
                            <td>
<?php
}
?>                            
                                <input data-bitzer-label="Modified On"
                                       data-bitzer-help-text="The record was last modified on this date."
                                       data-bitzer-type="datetime"
                                       readonly
                                       type="text" name="last_modified_on" value="<?php echo $date_modified ?>" >
<?php
if (!$isBitzer) {
?>                                       
                            </td>
                        </tr>
                    </table>

                    <br>
                    <table>
                        <tr><td>
                                <ul class="postnav">
                                    <li><a href="javascript:document.Campaigns.submit();">Save</a></li>
                                </ul>
                            </td>
                            <td>&nbsp;&nbsp;&nbsp;
                            </td>
                            <td>
                                <ul class="postnav">
                                    <li><a href="CampaignsList.php">Cancel</a></li>
                                </ul>
                            </td>
                        </tr>
                    </table>
<?php
}
?>                    
                </form>
<?php
if (!$isBitzer) {
?>
            </div>
            <div id="footer"></div>
        </div>
<?php
}
?>
    </body>
</html>